import { reportEvent } from "@/api/fortune";

// 页面浏览埋点，10秒后自动上报
export function trackPageView(data = {}) {
  let timer = null;
  let hasReported = false;

  function start() {
    timer = setTimeout(() => {
      reportEvent({
        reportKey: data.reportKey,
        reportVal: data.reportVal,
        pageName: data.pageName,
      });
      hasReported = true;
    }, 10000); // 10秒
  }

  function stop() {
    if (timer) clearTimeout(timer);
  }
  return { start, stop };
}

// 按钮点击埋点
export function trackButton(data = {}) {
  reportEvent({
    reportKey: data.reportKey,
    reportVal: data.reportVal,
    pageName: data.pageName,
  });
}

// 支付行为埋点
export function trackPayment(data = {}) {
  reportEvent({
    reportKey: data.reportKey,
    reportVal: data.reportVal,
    pageName: data.pageName,
  });
}
